/**
 * 地区级连组件（原b2c模块）
 * 由于调用的是原b2c的接口，组件不建议使用
 */
import Cascader from '../../el/ItemComponent/Cascader';
import * as React from 'react';
import requests from '@/utils/request';

interface Props {
  onChange?: Function;
  value?: any;
  level?: string | number;
  disabled?: boolean;
}
// 陈英杰修改 加入onChange  value的入参

/**
 * 获取省份数据
 * @param value
 * @param level
 * @returns
 */
const getProvinceList = (value, level) => {
  return requests('/yst-b2c/com/comArea/findAllProvince', {
    method: 'post',
    query: {
      ids: value,
      level
    }
  });
};

/**
 *获取城市数据
 * @param id
 * @returns
 */
const findChildrenById = (id: number | string) => {
  return requests(`/yst-b2c/com/comArea/findChildrenById/${id}`, {
    method: 'get'
  });
};

class RegionCascader extends React.Component<Props> {
  static defaultProps = {
    disabled: false
  };

  render() {
    const { value, onChange, level, disabled } = this.props;
    return (
      <Cascader
        request={getProvinceList}
        getData={findChildrenById}
        value={value}
        level={level}
        onChange={onChange}
        disabled={disabled}
      />
    );
  }
}
export default RegionCascader;
